package com.yangke.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wyk
 * @create 2022--10--12:56
 */
@Configuration
public class GateWayConfig {
    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder routeLocatorBuilder){
        /**
         * 路由定位器RouteLocatorBuilder
         */
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();

        /**
         * 使用GateWay可以在不暴露端口号的情况下，进行资源的访问
         */
        routes.route("path_route_yangke",
                r ->r.path("/guonei")
        .uri("http://news.baidu.com/guonei")).build();

        routes.route("path_route_yk",
                r ->r.path("/taobao")
                        .uri("https://www.taobao.com")).build();
        return routes.build();
    }
}
